﻿@model IEnumerable<EC_ASS.Models.Category>
<table class="table table-bordered">
    <thead>
        <th>Tên</th>
        <th>Mô tả</th>
        <th>Mã</th>
        <th>Thao tác</th>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr class="success">
                <td>@item.Name</td>
                <td>@item.Description</td>
                <td>@item.Prefix</td>
                <td>
                    @Html.ActionLink("Cập nhật", "EditCategory", "Admin", null, new { @class = "btn edit-category", @categoryID = item.ID })
                    @Html.ActionLink("Xóa", "DeleteCategory", "Admin", null, new {  @class = "btn delete-category", @categoryID = item.ID })
                </td>
            </tr>
        }
    </tbody>
</table>
<script type="text/javascript">
    $(function () {
        $('.edit-category').click(function () {
            var itemID = $(this).attr('categoryID');
            var editUrl = this.href + '/' + itemID;
            $('#editModalContent').load(editUrl, function () {
                $('#editModal').modal({
                    backdrop: 'static',
                    keyboard: true
                }, 'show');
                $('#editLoading').hide();
            });
            return false;
        });

        $('.delete-category').click(function () {
            var catID = $(this).attr('categoryID');
            var deleteUrl = this.href;
            $.ajax({
                type: "GET",
                url: deleteUrl,
                data: { id: catID },
                success: function (result) {
                }
            });
            setTimeout(function () {
                $('#listTable').load('@Url.Action("_ListCategory", "Admin")').hide().fadeIn('slow');
            }, 2000);
            return false;
        });
    });
</script>
